<template>
  <div class="components-container">
    <!-- <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">炉子编号</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.CrenameLike" placeholder="请输入火化炉编号"></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">逝者姓名</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.RegnameLike" placeholder="请输入逝者姓名"></el-input>
        </div>
      </div>
      <div v-if="hidden === 1" class="layui-inline">
        <label class="layui-form-label">火化工</label>
        <div class="layui-input-inline">
          <el-select v-model="selectData.Crhoprusr" placeholder="请选择火化炉编号" style="width:100%">
            <el-option v-for="item in creUSES" :key="item.STAID" :label="item.STANAME" :value="item.STAID">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.CrhbegdateSta" type="date" placeholder="请选择日期">
          </el-date-picker>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.CrhbegdateEnd" type="date" placeholder="请选择日期">
          </el-date-picker>
        </div>
      </div>
      <el-button type="primary" @click="getData">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div> -->
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <!--操作弹窗  -->
    <subsidyBalanceMain ref="dialog"  @refreshData="getData"> </subsidyBalanceMain>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-form-item {
  margin-bottom: 0px;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import subsidyBalanceMain from "./subsidyBalanceMain";
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
const SUBMISSION = "提交";
const NOSUBMISSION = "取消提交";
export default {
  name: "creUse",
  mixins: [manage],
  data() {
    return {
      selectData: {},
      // 火化工
     
      isUse: null,
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case ADD:
          this.$refs.dialog.open(this.order);
          break;
        case INFO:
          this.$refs.dialog.open(this.order,this.currentRow.BSBID);
          break;
        case DELETE:
          this.dataDelete();
          break;
        case SUBMISSION:
          this.SUBMISSION();
          break;
        case NOSUBMISSION:
          this.NOSUBMISSION();
          break;
        default:
      }
    },
    btnShow(val){
      switch(val){
        case ADD:
          return true;
          break;
        case DELETE:
        case MODIFY:
        case INFO:
        case SUBMISSION:
        case NOSUBMISSION:
          // if(this.currentRow) return true;
          return true;
          break;
        default:
      }
    },
    //获取表头
    getCreColumn() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Column.GetSubsidyBalanceColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
   
    //获取查询数据
    getData() {
      // let Data = JSON.parse(JSON.stringify(this.selectData));
      // Data.CrhbegdateSta = formatDate(Data.CrhbegdateSta, "yyyyMMdd");
      // Data.CrhbegdateEnd = formatDate(Data.CrhbegdateEnd, "yyyyMMdd");
      let Data;
      var data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Subsidy.QuerBsb, 
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //删除
    dataDelete() {
      var data = {
        BSBID: this.currentRow.BSBID
      };
      this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Subsidy.DeleteBsb,
            res => {
              this.getData();
              this.$message({
                message: "删除数据成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //提交
    NOSUBMISSION(){
      var data = {
        CRHID: this.currentRow.CRHID
      };
      this.$confirm("是否提交该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().CremationUse.Delete,
            res => {
              this.getData();
              this.$message({
                message: "提交补贴数据成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
     //取消提交
    NOSUBMISSION(){
      var data = {
        CRHID: this.currentRow.CRHID
      };
      this.$confirm("确认取消提交?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().CremationUse.Delete,
            res => {
              this.getData();
              this.$message({
                message: "取消提交补贴数据成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //重置查询
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
  },

  components: {
    subsidyBalanceMain,
    dataTable
  },
  created() {
    this.getCreColumn();
    this.getData();
  }
};
</script>